package com.soulmate.order.controller;

import common.pojo.Order;
import common.vo.SysResult;
import com.soulmate.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("order/manage")
public class OrderController {
    @Autowired
    private OrderService orderService=null;
    /**
     * 新增订单数据
     */
    @RequestMapping("/save")
    public SysResult addOrder(Order order){
        try {
            orderService.addOrder(order);
            return SysResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return SysResult.build(400,"fail",null);
        }
    }
    /**
     * 查询我的订单
     */
    @RequestMapping("/query/{userId}")
    public List<Order> queryMyOrders(@PathVariable("userId") String userId){
        return orderService.queryMyOrders(userId);
    }
    /**
     * 删除订单
     */
    @RequestMapping("/delete/{orderId}")
    public SysResult deleteOrder(@PathVariable("orderId") String orderId){
        try {
            orderService.deleteOrder(orderId);
            return SysResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return SysResult.build(400,"fail",null);
        }
    }


}
